package com.yanqu.road.server.cmd.activity.peakseacraft.cross;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.peakseacraft.config.PeakSeacraftLastGuessConfig;
import com.yanqu.road.entity.activity.seacraft.config.SeacraftSouthSeaGuessConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.PeakSeacraftProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.peakseacraft.PeakSeacraftMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;

/**
 * @Description
 */
@Cmd(code = GameProtocol.S_PEAK_SEACRAFT_RECEIVE_GUESS_REWARD_FROM_CROSS, desc = "海上争霸 南海丝路 领取竞猜奖励 跨服返回区服 协议")
public class PeakSeacraftReceiveGuessRewardFromCrossCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        PeakSeacraftProto.PeakSeacraftReceiveGuessRewardCrossToGameMsg crossToGameMsg = PeakSeacraftProto.PeakSeacraftReceiveGuessRewardCrossToGameMsg.parseFrom(packet.getBytes());
        ActivityInfo activityInfo = ActivityMgr.getOpenActivityInfo(crossToGameMsg.getActivityId());
        if (null == activityInfo){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        PeakSeacraftProto.PeakSeacraftReceiveGuessRewardRespMsg.Builder stcMsg = PeakSeacraftProto.PeakSeacraftReceiveGuessRewardRespMsg.newBuilder();
        if (activityInfo.getType() == eActivityType.PeakSeacraftActivity.getValue()) {
            stcMsg.setRet(crossToGameMsg.getRet());
            if(crossToGameMsg.getRet() == 0){
                for (PeakSeacraftLastGuessConfig guessConfig : PeakSeacraftMgr.getConfig().getGuessList()) {
                    if (guessConfig.getId() == crossToGameMsg.getNum()) {
                        // 加奖励
                        player.getModule(CurrencyModule.class).addCurrency(guessConfig.getAward(), eLogMoneyType.PeakSeacraftActivity, eLogMoneyType.PeakSeacraftActivityGuessReward);
                        stcMsg.setReward(guessConfig.getAward());
                        break;
                    }
                }
            }
        } else {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
        }


        player.sendPacket(ClientProtocol.U_PEAK_SEACRAFT_RECEIVE_GUESS_REWARD, stcMsg);
    }

    @Override
    public void sendData(GamePlayer player) {
    }
}
